import config from "@/config/config.json";
import { getSumyqFn } from '@/api/register'
import { useAppStore, useUserStore } from '@/store';
import { getToken } from "@/utils/auth";
import projectConfig from '@/config/project/index'


import { ref } from 'vue'



const inviteCode = ref('')






export default {
  async onShareAppMessage() {
    const userInfo = ref(useUserStore().userInfo);
    const siteInfo = useAppStore().siteInfo

    // const res = await getSumyqFn()
    // console.log(res, 123131313123131312);

    // if (res?.code === 200) {
    //   inviteCode.value = res.data.inviteUrl.split('').slice(res.data.inviteUrl.indexOf('inviteCode')).join('')
    //   console.log(inviteCode.value);
    // }

    inviteCode.value = userInfo.value?.inviteCode

    return {
      title: `你的朋友「 ${userInfo.value.nickname} 」邀请你加入${siteInfo.siteName}~`,
      // path: `/pages/webview/index?url=${encodeURIComponent(`${config.siteDomain}/#/silentLogin?${inviteCode.value}&mp_redirect=/pages/loginTransit/index&source=invite`)}`,
      path: `/pages/painting/index?inviteCode=${inviteCode.value}`,
      imageUrl: '/static/imgs/invite/1.png'
    }
  },
  onShareTimeline() {
    const siteInfo = useAppStore().siteInfo
    const userInfo = ref(useUserStore().userInfo);
    if (getToken() && userInfo.value.level > 0) {
      uni.setStorageSync('doTaskGetReward', true)
    }
    inviteCode.value = userInfo.value?.inviteCode
    return {
      title: `${siteInfo.shareContent} `,
      query: `inviteCode = ${inviteCode.value} `,
      imageUrl: projectConfig.share.imgPath
    }

  }
}